home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Development Tools & Languages / AEGestalt / ULookupCommand.cp < prev    next >
Encoding:
Text File  |  1995-02-12  |  3.6 KB  |  130 lines  |  [TEXT/MPS ]

  1. //    ULookupCommand.cp
  2. //     Copyright © 1991-92 by Apple Computer, Inc. All rights reserved.
  3. //    Kent Sandvik DTS
  4. //    This file contains all the member functions for TLookupCommand,
  5. //    for instance the PPC browsing handling.
  6. //
  7. //    <1>        khs        1.0        First final version
  8.  
  9.  
  10. #ifndef __ULOOKUPCOMMAND__
  11. #include "ULookupCommand.h"
  12. #endif
  13.  
  14. #ifndef __UAEDOCUMENT__
  15. #include "UAEDocument.h"
  16. #endif
  17.  
  18. //    METHODS:
  19. //    Empty constructor - for avoiding ptabs in global data space
  20.  
  21.  
  22.  
  23. #undef Inherited
  24. #define Inherited TCommand
  25.  
  26. #pragma segment ARes
  27. DefineClass(TLookupCommand, TCommand);
  28.  
  29. TLookupCommand::TLookupCommand()
  30. {
  31. }
  32.  
  33.  
  34. //    Initialize TLookupCommand, used for opening the PPCBrowser window
  35. #pragma segment ASelCommand
  36. void TLookupCommand::ILookupCommand(CommandNumber theNum,
  37.                                            TAEDocument* theDoc)
  38. {
  39.     fDocument = theDoc;
  40.     this->ICommand(theNum, NULL, kCantUndo, kDoesNotCauseChange, NULL);
  41. }
  42.  
  43.  
  44. //    MyPPCBrowserFilter - filter for the PPC Browser with information
  45. //    about what to look for over the network, i.e. who we can talk with.
  46. //     Thanks to Eric Soldan and his Kibitz application for the tips
  47. //    on how to implement this function.
  48. #pragma segment ASelCommand
  49. pascal  Boolean MyPPCBrowserFilter(LocationNamePtr/*theLocation*/,
  50.                                          PortInfoPtr thePortInfo)
  51. {
  52.     OSType type;
  53.  
  54.     if (thePortInfo->name.portKindSelector == ppcByString)
  55.     // go through every PPC port, and select the one that has the right signature
  56.     {
  57.         BlockMove(thePortInfo->name.u.portTypeStr + 1, Ptr(&type), sizeof(type));
  58.         // The BlockMove is so that we don't get an address error
  59.         // on a 68000-based machine due to referencing a long at
  60.         // an odd-address.
  61.         if (type == kSignature)
  62.             return TRUE;                        // found node
  63.     }
  64.     return FALSE;                                // did not see any
  65. }
  66.  
  67.  
  68. //    Do a PPC Browser lookup of existing nodes that talk the same protocol,
  69. //    i.e. an open application with the same signature
  70. #pragma segment ADoCommand
  71. void TLookupCommand::DoIt()
  72. {
  73.     FailInfo fi;
  74.     TargetID theTargetID;
  75.     PortInfoRec thePortInfo;
  76.     AEAddressDesc targetAddress;
  77.     CStr255 thePrompt = "Find node you want to examine";
  78.     CStr255 theType = "AEGestalt Nodes";
  79.     CStr255 windowTitle;
  80.     PPCFilterUPP myPPCFilterUPP;
  81.     
  82.     Try(fi)
  83.  
  84.     {
  85.         myPPCFilterUPP = NewPPCFilterProc(MyPPCBrowserFilter);
  86.         FailOSErr(PPCBrowser(thePrompt, theType, FALSE, &(theTargetID.location), &thePortInfo, myPPCFilterUPP, (CStr255)""));
  87.         DisposeRoutineDescriptor(myPPCFilterUPP);
  88.         fi.Success();
  89.     }
  90.     else
  91.     {
  92.         fDocument->fOKNode = FALSE;
  93.         if (fi.error == userCanceledErr)
  94.             return;
  95.         else
  96.             fi.ReSignal();
  97.     }
  98.  
  99.     // signal in document we found OK node
  100.     fDocument->fOKNode = TRUE;
  101.  
  102.     // enable the report button in document as well
  103.     fDocument->fReportButton->DimState(FALSE, TRUE);
  104.  
  105.     // get the AE Address
  106.     theTargetID.name = thePortInfo.name;
  107.     FailOSErr(AECreateDesc(typeTargetID, Ptr(&theTargetID), sizeof(theTargetID), &targetAddress));
  108.     fDocument->fAEGestaltAddress = targetAddress;
  109.  
  110.     // fix window title, so it will have the title of the port name
  111.     switch (theTargetID.location.locationKindSelector)
  112.     {
  113.         case ppcNoLocation:                        // my own machine
  114.             fDocument->SetTitle(CStr255("This is a local node"));
  115.             break;
  116.         case ppcNBPLocation:                    // we are handling this case
  117.             BlockMove(&theTargetID.location.u.nbpEntity.objStr, &windowTitle, 33);
  118.             fDocument->SetTitle(windowTitle);
  119.             break;
  120.         case ppcNBPTypeLocation:                // not handling it yet
  121.             break;
  122.     }
  123.     //    Words of wisdom, the nbpEntity record is trash if the PPC selection is on the same
  124.     //    local node. It is very important to check the locationKindSelector (as above) and
  125.     //    only use the npbEntity record when we have a ppcNBPLocation!!! See IM VI-7 for more
  126.     //    information about this (it's well hidden!)
  127. }
  128.  
  129.  
  130.